package com.ebuy.model;

import java.util.List;

/**
 * 分页类
 * @author zmzy
 *
 */
public class Pager<T> {
	private Integer pageIndex;  //当前页
	private int pageOffset;  //偏移量
	private int pageSize = 2;  //页大小
	private int totalPage;  //总页数
	private int count;  //总记录数
	private List<T> datas;
	public Integer getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(Integer pageIndex) {
		if(pageIndex == null || pageIndex <= 0){
			pageIndex = 1;
		}
		if(pageIndex>=getTotalPage()){
			pageIndex = totalPage;
		}
		this.pageIndex = pageIndex;
	}
	public int getPageOffset() {
		pageOffset = (pageIndex-1)*pageSize;
		//当前也从第几个商品开始的计算公式（当前页-1）×当前页的总数
		//eg:第一页0,3==>显示0-2的三个商品
		//   第二页3,3==>显示3-5的三个商品
		return pageOffset;
	}
	public void setPageOffset(int pageOffset) {
		this.pageOffset = pageOffset;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalPage() {
//		totalPage = (int)Math.ceil(((double)count/pageSize));
		totalPage = (count + pageSize - 1)/pageSize;
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	public List<T> getDatas() {
		return datas;
	}
	public void setDatas(List<T> datas) {
		this.datas = datas;
	}
}
